<?php
/**
 * +--------------------------------------------------------------
 * | eLuoPHP
 * +--------------------------------------------------------------
 * | Copyright (c) 2016-2018 http://qxwoo.cn All rights reserved.
 * +--------------------------------------------------------------
 * | y139w [y139w@163.com]
 * +--------------------------------------------------------------
 * | JSON类型响应类文件
 * +--------------------------------------------------------------
 */

namespace luo\response;


use luo\{Exception, Response};

class Json extends Response
{

    /**
     * 页面响应内容类型
     * @var string
     */
    protected $contentType = 'application/json';

    /**
     * 处理响应内容
     * @param $data
     * @return mixed|string
     * @throws Exception
     */
    protected function output($data){

        $data = json_encode($data, JSON_UNESCAPED_UNICODE);
        if(false === $data){
            throw new Exception('JSON转换失败');
        }

        return $data;

    }

}